
$(
    function () {
        findById();
    }
)






layui.use('form',function () {
    let form = layui.form
    form.on('submit(edit)',function (data) {
        data = data.field;
        data.loginName=sessionStorage.getItem("loginName")
        data.id=sessionStorage.getItem("navId");

        $.ajax({
            url:'/back/nav/edit',
            data:data,
            dataType:'json',
            type:'post',
            success:function (data) {
                if(data.result=="notLogin"){
                    window.open("/html/login.html", "_top");
                }
                console.log(data);
                if (data.result == "success") {
                    //发异步，把数据提交给php
                    layer.alert("修改成功", {
                            icon: 6
                        },
                        function () {
                            //关闭当前frame
                            xadmin.close();

                            // 可以对父窗口进行刷新
                            xadmin.father_reload();
                        });
                } else {
                    layer.alert("修改失败", {
                        icon: 1
                    });
                }
            }

        });
        return false;

    })
})

function findById() {
    let id = sessionStorage.getItem("navId");
    console.log(id)
    $.ajax({
        url:'/back/nav/findInfo',
        type:'get',
        dataType:'json',
        data:{id:id,loginName:sessionStorage.getItem("loginName")},
        success:function (res) {
            if(res.result=="notLogin"){
                window.open("/html/login.html", "_top");
            }
            let data = res.data
            $("#title").val(data.title);
           $("#href").val(data.href)


            console.log(res)
        }
    })

}

